import axios from '@/libs/api.request'

export const login = ({ userName, password, uuid, captcha, address }) => {
  const data = {
    'username': userName,
    'password': password,
    'uuid': uuid,
    'captcha': captcha,
    'address': address
  }
  return axios.request({
    url: 'sys/login',
    data,
    method: 'post'
  })
}
export const getAddress = (data) => {
  var xmlhttp
  if (window.XMLHttpRequest) {
    //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
    xmlhttp = new XMLHttpRequest()
  } else {
    // IE6, IE5 浏览器执行代码
    xmlhttp = new ActiveXObject('Microsoft.XMLHTTP')
  }
  xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
      data.address = xmlhttp.responseText
    }
  }
  xmlhttp.open('GET', 'http://ip-api.com/json/?lang=zh-CN', false)
  xmlhttp.send()
}

export const logout = () => {
  return axios.request({
    url: 'sys/logout',
    method: 'post'
  })
}
